<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @cancel="handleCancel"
    @ok="handleOk"
    :body-style="{
      padding: '10px'
    }"
    cancelText="关闭"
  >
    <GenerateProductEntry ref="entry" @ok="close"></GenerateProductEntry>
  </j-modal>
</template>

<script>
import GenerateProductEntry from '@views/production/modules/generateProduct/GenerateProductEntry.vue'
import { postAction } from '@api/manage'

export default {
  name: 'GenerateProductPreview',
  components: { GenerateProductEntry },
  props: {
    sourceId: {
      type: String,
      default: ''
    },
    sourceSerial: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      title: '生成领料单',
      width: 1200,
      visible: false,
      confirmLoading: false,
      dataSource: [],
      url: {
        list: '/production/hfRouting/stepSelectByProductInput'
      }
    }
  },
  methods: {
    loadData(missionDetailList) {
      this.confirmLoading = true
      postAction(this.url.list, missionDetailList)
        .then(res => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
            this.$refs.entry.loadData1([...this.dataSource])
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.confirmLoading = false
        })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    handleOk() {
      this.confirmLoading = true
      let b = this.$refs.entry.handleOk(this.sourceId, this.sourceSerial)
      if (!b) {
      } else {
        this.close()
      }
      this.confirmLoading = false
    }
  }
}
</script>

<style scoped></style>
